﻿<UserControl x:Class="TfsBuildManager.Views.BuildsGrid"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:Controls="clr-namespace:TfsBuildManager.Controls;assembly=TFSBuildManager.Controls" 
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="600">
  <UserControl.Resources>
    <ResourceDictionary Source="/TFSBuildManager.Views;component/Themes/ResourceDictionary.xaml"/>
  </UserControl.Resources>  
  <Grid>
    <Grid.Resources>
    </Grid.Resources>

    <Controls:SortableListView x:Name="BuildList" ItemsSource="{Binding Builds}" Margin="0,-1,0,-1"
                                   ColumnHeaderSortedAscendingTemplate="HeaderTemplateArrowUp" 
                                   ColumnHeaderSortedDescendingTemplate="HeaderTemplateArrowDown" 
                                   ColumnHeaderNotSortedTemplate="HeaderTemplateTransparent" MouseDoubleClick="OnMouseDoubleClick"
                               Style="{StaticResource ResourceKey=ListViewStyle}">
          <ListView.Resources>
                <DataTemplate x:Key="StatusTemplate">
                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
                        <StackPanel.ToolTip>
                            <ToolTip Content="{Binding BuildStatus}"></ToolTip>
                        </StackPanel.ToolTip>
                        <Image Source="{Binding Status}" Width="16" Height="16"/>
                    </StackPanel>
                </DataTemplate>
                <DataTemplate x:Key="NameTemplate">
                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
                        <TextBlock Text="{Binding Name}" Margin="3,0,0,1" VerticalAlignment="Bottom"/>
                    </StackPanel>
                </DataTemplate>
                <DataTemplate x:Key="BuildDefinitionTemplate">
                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
                        <TextBlock Text="{Binding BuildDefinition}" Margin="3,0,0,1" VerticalAlignment="Bottom"/>
                    </StackPanel>
                </DataTemplate>                
                <DataTemplate x:Key="TeamProjectTemplate">
                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
                        <TextBlock Text="{Binding TeamProject}" Margin="3,0,0,1" VerticalAlignment="Bottom"/>
                    </StackPanel>
                </DataTemplate>
                <DataTemplate x:Key="QueuedTimeTemplate">
                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
                        <TextBlock Text="{Binding QueuedTime}" Margin="3,0,0,1" VerticalAlignment="Bottom"/>
                    </StackPanel>
                </DataTemplate>
                <DataTemplate x:Key="StartTimeTemplate">
                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
                        <TextBlock Text="{Binding StartTime}" Margin="3,0,0,1" VerticalAlignment="Bottom"/>
                    </StackPanel>
                </DataTemplate>
                <DataTemplate x:Key="FinishTimeTemplate">
                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
                        <TextBlock Text="{Binding FinishTime}" Margin="3,0,0,1" VerticalAlignment="Bottom"/>
                    </StackPanel>
                </DataTemplate>
                <DataTemplate x:Key="DurationTemplate">                    
                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
                        <TextBlock Text="{Binding Duration}" Margin="3,0,0,1" VerticalAlignment="Bottom"/>
                    </StackPanel>
                </DataTemplate>              
                <DataTemplate x:Key="DropLocationTemplate">
                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
                        <TextBlock Text="{Binding DropLocation}" Margin="3,0,0,1" VerticalAlignment="Bottom"/>
                    </StackPanel>
                </DataTemplate>                
                <DataTemplate x:Key="QualityTemplate">
                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
                        <TextBlock Text="{Binding Quality}" Margin="3,0,0,1" VerticalAlignment="Bottom"/>
                    </StackPanel>
                </DataTemplate>
                <DataTemplate x:Key="RequestedByTemplate">
                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
                        <TextBlock Text="{Binding RequestedBy}" Margin="3,0,0,1" VerticalAlignment="Bottom"/>
                    </StackPanel>
                </DataTemplate>
                <DataTemplate x:Key="BuildAgentTemplate">
                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
                        <TextBlock Text="{Binding BuildAgent}" Margin="3,0,0,1" VerticalAlignment="Bottom"/>
                    </StackPanel>
                </DataTemplate>
                <DataTemplate x:Key="BuildControllerTemplate">
                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
                        <TextBlock Text="{Binding BuildController}" Margin="3,0,0,1" VerticalAlignment="Bottom"/>
                    </StackPanel>
                </DataTemplate>
                <DataTemplate x:Key="KeepForeverTemplate">
                    <Image Source="{Binding KeepForever}" Width="16" Height="16"/>                
                </DataTemplate>                
                <Style TargetType="{x:Type GridViewColumnHeader}">
                    <Setter Property="Margin" Value="0,0,0,0" />
                    <Setter Property="HorizontalContentAlignment" Value="Left" />
                </Style>
      </ListView.Resources>

      <ListView.View>
                <GridView>
                    <Controls:SortableGridViewColumn Header="" SortPropertyName="KeepForever" IsDefaultSortColumn="False" CellTemplate="{StaticResource KeepForeverTemplate}"/>                    
                    <Controls:SortableGridViewColumn Header="" SortPropertyName="Status" IsDefaultSortColumn="False" CellTemplate="{StaticResource StatusTemplate}"/>
                    <Controls:SortableGridViewColumn Header="Name" SortPropertyName="Name" IsDefaultSortColumn="False" CellTemplate="{StaticResource NameTemplate}"/>
                    <Controls:SortableGridViewColumn Header="Build Definition" SortPropertyName="BuildDefinition" IsDefaultSortColumn="False" CellTemplate="{StaticResource BuildDefinitionTemplate}"/>
                    <Controls:SortableGridViewColumn Header="Queued Time" SortPropertyName="SortableQueuedTime" IsDefaultSortColumn="False" CellTemplate="{StaticResource QueuedTimeTemplate}"/>
                    <Controls:SortableGridViewColumn Header="Start Time" SortPropertyName="SortableStartTime" IsDefaultSortColumn="False" CellTemplate="{StaticResource StartTimeTemplate}"/>
                    <Controls:SortableGridViewColumn Header="Finish Time" SortPropertyName="SortableFinishTime" IsDefaultSortColumn="True" CellTemplate="{StaticResource FinishTimeTemplate}" DefaultSortDirection="Descending"/>
                    <Controls:SortableGridViewColumn Header="Duration" SortPropertyName="Duration" IsDefaultSortColumn="False" CellTemplate="{StaticResource DurationTemplate}"/>
                    <Controls:SortableGridViewColumn Header="Requested By" SortPropertyName="RequestedBy" IsDefaultSortColumn="False" CellTemplate="{StaticResource RequestedByTemplate}"/>
                    <Controls:SortableGridViewColumn Header="Agent" SortPropertyName="BuildAgent" IsDefaultSortColumn="False" CellTemplate="{StaticResource BuildAgentTemplate}"/>
                    <Controls:SortableGridViewColumn Header="Controller" SortPropertyName="BuildController" IsDefaultSortColumn="False" CellTemplate="{StaticResource BuildControllerTemplate}"/>
                    <Controls:SortableGridViewColumn Header="Drop Location" SortPropertyName="DropLocation" IsDefaultSortColumn="False" CellTemplate="{StaticResource DropLocationTemplate}" />
                    <Controls:SortableGridViewColumn Header="Build Quality" SortPropertyName="Quality" IsDefaultSortColumn="False" CellTemplate="{StaticResource QualityTemplate}"/>
                    <Controls:SortableGridViewColumn Header="Team Project" SortPropertyName="TeamProject" IsDefaultSortColumn="False" CellTemplate="{StaticResource TeamProjectTemplate}"/>
                </GridView>
            </ListView.View>
        </Controls:SortableListView>
  </Grid>

</UserControl>
